package cn.xiaomubiao.oschine.adapter.myinfo_message;

import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.Spanned;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.xiaomubiao.oschine.R;
import cn.xiaomubiao.oschine.base.BaseRecyclerViewAdapter;
import cn.xiaomubiao.oschine.bean.Active;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by hasee on 2017/4/7.
 */

public class AtMeAdapter extends BaseRecyclerViewAdapter {


    private final List<Active> mActives;

    public AtMeAdapter( List<Active> actives ) {
        mActives = actives;
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder( ViewGroup parent, int viewType ) {
//        View view = View.inflate(parent.getContext(), R.layout.view_myinfo_message_at_me, null);
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_myinfo_message_at_me, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder( RecyclerView.ViewHolder holder, int position ) {
        ViewHolder viewHolder = (ViewHolder) holder;
        Glide.with(viewHolder.itemView.getContext()).load(mActives.get(position).getPortrait()).into(viewHolder.mIvHeaderPhoto);
        viewHolder.mTvUsername.setText(mActives.get(position).getAuthor());
        Spanned spanned = Html.fromHtml(mActives.get(position).getMessage());
        viewHolder.mTvContent.setText(spanned);
        viewHolder.mTvTime.setText(mActives.get(position).getPubDate());


        super.onBindViewHolder(holder, position);
    }

    @Override
    public int getItemCount() {
        return mActives != null ? mActives.size() : 0;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_header_photo)
        CircleImageView mIvHeaderPhoto;
        @BindView(R.id.tv_username)
        TextView mTvUsername;
        @BindView(R.id.tv_time)
        TextView mTvTime;
        @BindView(R.id.tv_content)
        TextView mTvContent;


        public ViewHolder( View itemView ) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
